* Reset settings and initialize log file
launch, path("share/overall")

*-------------------------------------------------------------------------------
* Price and Wasserman (2024), "The Summer Drop in Female Employment"
*
* Description: Show seasonal movements in EPOP, UPOP, and NPOP.
*-------------------------------------------------------------------------------


* Prepare data and run models
*-------------------------------------------------------------------------------

if "$estimate" != "0" {
	* Compute EPOP, UPOP, and non-participation rates
	gzuse "$basepath/data/derived/cps_bms_sample.dta.gz", clear
	gcollapse (mean) emp unemp nlf (rawsum) wtfinl (first) month tmspline* weeks [pw = wtfinl], by(female tm)
	tsset female tm

	* Loop over sex and outcomes
	foreach f of numlist 0 1 {
		foreach yvar of varlist emp unemp nlf {
			* Run the specification
			quietly ivreg2 `yvar' ib5.month tmspline* weeks if female == `f' [aw = wtfinl], bw($bandwidth) robust small
			process_estimates, path("overall") model("f`f'_`yvar'")

			* Record average outcomes as of May
			quietly sum `yvar' if female == `f' & month == 5 [aw = wtfinl]
			quietly estadd scalar may_mean = r(mean)
			estimates save "$basepath/models/overall/f`f'_`yvar'.ster", replace
		}
	}
}


* Prepare estimates
*-------------------------------------------------------------------------------

* Load estimates into memory
load_estimates, path("overall")

* Prepare coefficient labels for each month
make_coeflabels


* Plot seasonality in employment, unemployment, and non-participation by sex
*-------------------------------------------------------------------------------

* Prepare background shading
clear
set obs 14
gen rlow = -1.6
gen rupp = 1.6
gen rval = _n - 0.5

* Plot estimates
foreach f of numlist 0 1 {
	if `f' == 0 local flbl "Men"
	if `f' == 1 local flbl "Women"

	#delimit ;
	coefplot
		(f`f'_emp, offset(-.1) recast(connected) color(black) ciopts(color(black) lwidth(thin)) label("Employment"))
		(f`f'_nlf, offset(+.000) recast(connected) color(gs8) ciopts(color(gs8) lwidth(thin)) label("Non-participation"))
		(f`f'_unemp, offset(+.1) recast(connected) color(gs8) mfcolor(white) ciopts(color(gs8) lwidth(thin)) label("Unemployment")),
		coeflabels(`coeflabels')
		title("{bf:`flbl'}")
		xtitle("")
		xlabel(, alternate)
		ytitle("")
		yscale(range(-1.6 1.6))
		ylabel(-1.5(.5)1.5, format(%5.1f))
		yline(0)
		addplot(
			rarea rupp rlow rval if inrange(rval, 0.5, 5.5), color($ltgs) plotregion(margin(t=0 b=0)) below ||
			scatteri 0 0.5 0 13.5, recast(line) color(black) below)
		vertical
		legend(rows(1) `legend_labels' size(*.8))
		rescale(100);
	#delimit cr

	tempfile g`f'
	graph save "`g`f''"
}

* Create pdf file
grc1leg "`g1'" "`g0'", l1title("      Difference relative to May (p.p.)", size(*.8)) imargin(vsmall)
nicepdf "$basepath/output/overall.pdf", panels(2) indirect replace

* Report the May-July drop in female employment in percent terms
estimates restore f1_emp
display e(may_mean)
display "Summer drop: " %5.2f `=100 * `=_b[coef2]'/`=e(may_mean)'' " percent"

* Close the log file
unlaunch
